<script setup>
import { onMounted, ref } from 'vue';
import axios from 'axios';
import {useStore} from '../stores/store.js';
import message from './message.vue';
import {useRouter} from 'vue-router';

const store = useStore();
const student = ref({});
const modal = ref();
const router = useRouter();
let id = ref();


onMounted(()=>{
    id.value = store.getstudentid
    console.log(id.value);
    getbyid()
})
const getbyid = async () => {
    axios({
        method:'get',
        url:'http://localhost:8080/student/getbyid',
        withCredentials: true,
        params:{
            id:id.value
        }
    }).then(function(response){
        student.value = response.data.data;
    })
}
const update = async () => {
    axios({
        method:'post',
        url:'http://localhost:8080/student/updateS',
        data:student.value,
        withCredentials: true
    }).then((response) => {
        modal.value.show(response.data);
        if(response.data.code === 1){
            setTimeout(() => (
                router.back()
            ), 1000);
        }
    })
}
</script>
<template>
    <div class="edit">
        <div class="title">
            <p>编辑</p>
        </div>
        <div class="edit-box">
            <p>姓名</p>
            <input type="text" v-model="student.studentName" class="name mr">
            <p>身份证号</p>
            <input type="text" v-model="student.studentIdCode" class="id mr">
            <p>性别</p>
            <input type="text" v-model="student.studentSex" class="sex mr">
            <p>民族</p>
            <input type="text" v-model="student.studentNation" class="nation mr">
            <button @click="update">提交</button>
        </div>
    </div>
    <message ref="modal"></message>
</template>
<style scoped>
.edit{
    width: 97%;
    margin: 5px;
}
.edit-box{
    height: 50%;
    display: flex;
    flex-direction: column;
    width: 100%;
    padding: 20px;
    padding-left: 40px;
    justify-content: space-around;
}
.edit-box p{
    display: block;
    color: rgb(120, 120, 120);
}
.edit-box input{
    display: block;
    width: 35%;
    height: 25px;
    border-radius: 30px;
    border: 1px solid #000;
    outline: none;
    padding-left: 10px;
}
button{
    width: 100px;
    height: 30px;
    background-color: rgb(0, 0, 0);
    color: white;
    border: none;
    border-radius: 5px;

}
</style>